#include <bits/stdc++.h>
using namespace std;

int k[1000005], n, a[200005];
long long ans;

void dfs(int x){
    if(x > n){
        int last1 = 0, lastmi1 = 0;
        long long sum = 0;
        for(int i = 1; i <= n; i++){
            if(k[i] == 1){
                if(a[i] == a[last1]) sum += a[i];
                last1 = i;
            }else{
                if(a[i] == a[lastmi1]) sum += a[i];
                lastmi1 = i;
            }
        }
        ans = max(ans, sum);
        return;
    }
    k[x] = 1;
    dfs(x + 1);
    k[x] = -1;
    dfs(x + 1);
}

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while(T--){
        memset(k, 0, sizeof k);
        ans = 0;
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
        k[1] = 1;
        dfs(2);
        cout << ans << '\n';
    }
    return 0;
}
